﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using YEBHI.EF;
using YEBHI.Entities;
using System.Data;
using YEBHI.Utilities;
namespace YEBHI.MVC.Controllers.ActionConrollers
{
    public class LayoutDataController : Controller
    {
        //
        // GET: /LayoutData/
        YEBHIEntities db = new YEBHIEntities();
        public ActionResult FeatureBrands()
        {
            int intSiteID = YebhiUtil.getSiteId(this.Request.Url.Host);
            var query = (
                from IAPA in db.IA_PRODUCT_ATTRIBUTE
                join IAPAI in db.IA_PRODUCT_ATTRIBUTE_IMAGE
                on IAPA.IAPA_ID equals IAPAI.IAPAI_IAPA_ID
                join IAH in db.IA_HOMEBRANDS
                on IAPA.IAPA_ID equals IAH.IAHB_IAPA_ID
                where IAH.IAHB_SITE_ID == intSiteID
                select new { IAPA.IAPA_ID, IAPA.IAPA_NAME, IAPAI.IAPAI_IMAGEPATH, IAPA.IAPA_FRIENDLY_NAME, IAH.IAHB_SITE_ID }
                        ).OrderBy(M => M.IAPA_NAME).Take(8);
            string appUrl = string.Empty;

            string strImagePath = YebhiUtil.GetImageServerPath();
            DataTable dtFeatureBrands = new DataTable();
            dtFeatureBrands.Columns.Add("brandUrl", typeof(String));
            dtFeatureBrands.Columns.Add("imageUrl", typeof(String));


            foreach (var item in query)
            {

                string strBrandUrl = string.Empty;
                string strImageUrl = string.Empty;
                strBrandUrl = appUrl + "online-shopping/" + item.IAPA_FRIENDLY_NAME + ".html";

                if (item.IAPAI_IMAGEPATH != null && item.IAPAI_IMAGEPATH != "")
                {
                    strImageUrl = strImagePath + "/upload/" + item.IAPAI_IMAGEPATH.Substring(item.IAPAI_IMAGEPATH.ToString().IndexOf("\\brandlogo")).Replace("\\", "/") ;
                }
                else
                {
                    strImageUrl = appUrl + "/attributeimages.aspx?type=full&id=" + item.IAPA_ID;

                }
                DataRow drowFeatureBrands = dtFeatureBrands.NewRow();
                drowFeatureBrands["brandUrl"] = strBrandUrl;
                drowFeatureBrands["imageUrl"] = strImageUrl;
                dtFeatureBrands.Rows.Add(drowFeatureBrands);

            }
            dtFeatureBrands.AcceptChanges();
            return PartialView(dtFeatureBrands);
        }
        public ActionResult Testimonial()
        {
            int intSiteID = YebhiUtil.getSiteId(this.Request.Url.Host);
            IA_TESTIMONIALS oTESTIMONIAL = db.IA_TESTIMONIALS
                .Where(M => M.IAT_FLAG == 1 && M.IAT_SITE_ID == intSiteID)
                .OrderBy(M => Guid.NewGuid())
                .FirstOrDefault();
            return PartialView(oTESTIMONIAL);
        }
    }
}
